package com.tjshop.android;

import com.tjshop.android.util.SharedPreferencesUtil;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.RelativeLayout;

public class DealWithNoGoodsActivity extends BaseActivity implements
		View.OnClickListener {

	RelativeLayout option1,option2,option3;
	CheckBox check1,check2,check3;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_nogoods);
		
		
		
		setTheme(R.style.Theme_Sherlock);
		updateCommonReturnBar("缺货登记",new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				complete();
			}
		});
		
		
		option1 = (RelativeLayout) findViewById(R.id.option1);
		option1.setOnClickListener(this);
		option2 = (RelativeLayout) findViewById(R.id.option2);
		option2.setOnClickListener(this);
		option3 = (RelativeLayout) findViewById(R.id.option3);
		option3.setOnClickListener(this);
		
		check1 = (CheckBox) findViewById(R.id.check1);
		check2 = (CheckBox) findViewById(R.id.check2);
		check3 = (CheckBox) findViewById(R.id.check3);
		
		String str = SharedPreferencesUtil.get(getApplicationContext(), "config", "remember_nogoods");
		if(str != null){
			if(str.equals("取消订单")){
				check2.setChecked(true);
				check1.setChecked(false);
				check3.setChecked(false);
			}else if(str.equals("与店主协商")){
				check2.setChecked(false);
				check3.setChecked(true);
				check1.setChecked(false);
			}else{
				check2.setChecked(false);
				check3.setChecked(false);
				check1.setChecked(true);
			}
		}
	}

	private void complete() {
		String str = "取消订单";
		if(check1.isChecked()){
			str = "等待所有商品备齐后再发";
		}else if(check3.isChecked()){
			str = "与店主协商";
		}
		Intent it = new Intent();  
        it.putExtra("result", str);  
		setResult(RESULT_OK, it);
		finish();
	}
	
	@Override
	public void onBackPressed() {
		complete();
		super.onBackPressed();
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.option1:
			check1.setChecked(true);
			check2.setChecked(false);
			check3.setChecked(false);
			break;
		case R.id.option2:
			check1.setChecked(false);
			check2.setChecked(true);
			check3.setChecked(false);
			break;
		case R.id.option3:
			check1.setChecked(false);
			check2.setChecked(false);
			check3.setChecked(true);
			break;
		default:
			break;
		}
	}


	@Override
	public boolean handleMessage(Message arg0) {
		// TODO Auto-generated method stub
		return false;
	}

}
